import { CacheService } from '@app/cache';
import { ConfigureService } from '@app/configure';
import { Injectable } from '@nestjs/common';
import * as dayjs from 'dayjs';

@Injectable()
export class AppService {
	constructor(
		private readonly cache:CacheService,
		private readonly config:ConfigureService
	) {}

	async f() {
		console.log(this.config.get("a"))
		const time = dayjs().unix()
		const cacheKey = 'asdfd1'
		const value = 333
		const data = await this.cache.hgetall(k)
		
		if(Object.keys(data).length == 0) { //这是第一次上报
			this.cache.hmset(cacheKey, {v : value, t : time})
			return
		}

		const prevValue = Number(data.v)

		if(value - prevValue > 10) {
			const prevTime = Number(data.t)
			if(prevTime - time <= 1800) { //30分钟内达到了10mm，执行采样
				this.cache.hmset(cacheKey, {v : value, t : time})
			}
		}

		

	}
}
